<template>
  <div>
    <el-form label-width="120px" :model="formData">
      <el-form-item label="Id">
        <el-input v-model="formData.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="formData.text"></el-input>
      </el-form-item>
      <el-form-item label="条件类型">
        <el-select v-model="formData.conditionType" clearable placeholder="请选择">
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="表达式类型" v-if="formData.conditionType">
        <el-select v-model="formData.expressionType" placeholder="请选择" @change="changeExpress" clearable>
          <el-option
              v-for="item in expressOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="表达式" v-if="formData.expressionType">
        <el-input v-model="formData.expression" :readonly="readonly"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: '',
  props: {
    nodeData: Object,
    lf: Object || String,
  },
  mounted() {
    const { properties, text,id } = this.$props.nodeData
    if (properties) {
      this.$data.formData = Object.assign({}, this.$data.formData, properties)
    }
    if (text && text.value) {
      this.$data.formData.text = text.value
    }
    if (id ) {
      this.$data.formData.id = id
    }
    if(this.$data.formData.expressionType=='3'){
      this.readonly=false
    }else{
      this.readonly=true
    }
  },
  data () {
    return {
      text: '',
      readonly:false,
      formData: {
          id:'',
          text:'',
          conditionType: '',
          expression: '',
          expressionType:''
        },
      options:[{
        value: '1',
        label: '表达式'
      }],
      expressOptions:[{
        value: '1',
        label: '同意'
      },
        {
          value: '2',
          label: '拒绝'
        },
        {
          value: '3',
          label: '其它'
        }]
    }
  }, 
  methods: {
    save() {
      const { id } = this.$props.nodeData
      this.$props.lf.setProperties(id, {
        ...this.$data.formData
      });
      this.$props.lf.updateText(id, this.$data.formData.text);
      this.$emit('onClose')
    },
    changeExpress(params){
      if(params=='1'){
        this.formData.expression="${approve==true}"
        this.readonly=true
      }
      if(params=='2'){
        this.formData.expression="${approve==false}"
        this.readonly=true
      }
      if(params=='3'){
        this.formData.expression=""
        this.readonly=false
      }
    }
  }
}
</script>
<style scoped>
</style>
